@use 'sass:math';
%border {
  position: absolute;
  content: ' ';
  top: 0;
  left: 0;
  -webkit-transform-origin: top left;
  transform-origin: top left;

  width: percentage(1);
  height: percentage(1);
  -webkit-transform: scale(1);
  transform: scale(1);

  @for $i from 2 through 3 {
    @media (-webkit-min-device-pixel-ratio: $i), (min-device-pixel-ratio: $i) {
      width: percentage($i);
      height: percentage($i);
      -webkit-transform: scale(math.div(1, $i));
      transform: scale(math.div(1, $i));
    }
  }
}

@function isPercentageUnit($value) {
  @return str_index($value + '', '%') != null;
}

@mixin hairline(
  $border-width: 1px,
  $border-color: #ccc,
  $border-radius: 0,
  $border-style: solid
) {
  &:after {
    border-width: $border-width;
    border-style: $border-style;
    border-color: $border-color;
    border-radius: $border-radius;

    @if isPercentageUnit($border-radius) == false {
      @for $i from 2 through 3 {
        @media (-webkit-min-device-pixel-ratio: $i),
          (min-device-pixel-ratio: $i) {
          border-radius: $border-radius * $i;
          border-width: $border-width * $i;
        }
      }
    }

    @extend %border;
  }
}

@mixin hairline-top($border-color: #ccc, $border-style: solid) {
  &:after {
    border-top: 1px $border-style $border-color;
    @extend %border;
  }
}

@mixin hairline-right($border-color: #ccc, $border-style: solid) {
  &:after {
    border-right: 1px $border-style $border-color;
    @extend %border;
  }
}

@mixin hairline-bottom($border-color: #ccc, $border-style: solid) {
  &:after {
    border-bottom: 1px $border-style $border-color;
    @extend %border;
  }
}

@mixin hairline-left($border-color: #ccc, $border-style: solid) {
  &:after {
    border-left: 1px $border-style $border-color;
    @extend %border;
  }
}
